template.defaults.imports.CountdownTime = function (factEndDate) {
    var timestamp = (new Date()).valueOf();
    return factEndDate - timestamp;
};

    var advTypeId = '';
    var loading = false; //状态标记
    var hasNextPage = false;
    var pageNo = 1;
    queryList(pageNo);

    //下拉刷新
    $("#aroundBox").pullToRefresh().on("pull-to-refresh", function () {
        $("#contentTo").html("");
        pageNo = 1;
        queryList(pageNo,function(){
            $("#aroundBox").pullToRefreshDone(); // 重置下拉刷新
        });
    });
  
    //上拉加载更多
    $('#aroundBox').infinite().on("infinite", function () {
        if (hasNextPage){
            pageNo++;
            queryList(pageNo,function(){
            },true);
        }        
    });

    function queryList(pageNo,callback,isMore){
        if (loading) return;
        loading = true;
        var params = {};
        params.start = (pageNo - 1) * 20;
        params.limit = 20;
         /* global getCookie visitUrl*/
        
        $.get('/antique/api/mallAdvInfo/query_adv_type_list', params, function (result) {
            if (result.code == 0) {
                if (!isMore){
                    /* global template */
                    document.getElementById('contentTo').innerHTML = template('content', result.data); 
                } else {
                    $("#contentTo").append(template('content', result.data));
                }
                hasNextPage = result.data.hasNextPage;
                if (!result.data.hasNextPage) {
                    $('#loadmore').hide();
                    $('#nomore').show();
                } else {
                    $('#loadmore').show();
                    $('#nomore').hide();
                }
                if (callback) callback();
                loading = false;

                $(".item").click(function () {
                    $(".item .weui-flex .weui-flex__item .placeholder .iconfont").removeClass("icon-radio1");
                    $(this).find(".weui-flex .weui-flex__item .placeholder .iconfont").addClass("icon-radio1");
                    
                    advTypeId = $(this).data('advid');
                });
            }

            
        });
    }

    function goAddAdv() {
        if (advTypeId == '') {
            $.toast("请选择您要投放的广告", "cancel");
            return ;
        }
        visitUrl("/add_adv?advTypeId=" + advTypeId,true);
    }

    

